<template>
  <page-card title="请假管理">

    <div>
      <a-card
        style="width:100%"
        :tab-list="tabListNoTitle"
        :active-tab-key="noTitleKey"
        @tabChange="key => onTabChange(key, 'noTitleKey')"
      >
        <div v-if="noTitleKey === 'Municipal'">
          <LeaveinfoListContentVue type="Municipal"></LeaveinfoListContentVue>
        </div>
        <div v-else-if="noTitleKey === 'county'">
          <LeaveinfoListContentVue type="county"></LeaveinfoListContentVue>
        </div>
        <div v-else-if="noTitleKey === 'leader'">
          <LeaveinfoListContentVue type="leader"></LeaveinfoListContentVue>
        </div>
        <div v-else="noTitleKey === 'police'">
          <LeaveinfoListContentVue type="police"></LeaveinfoListContentVue>
        </div>
      </a-card>
    </div>

  </page-card>
</template>
<script>
import { leaveInfoList, leaveInfoDel } from '@/api/leaveinfo'
import { PAGINATION, TABLE_STATUS_CELL } from '@zt/zongheng-pro/framework/constants'
import LeaveinfoListContentVue from './LeaveinfoListContent.vue'
export default {
  components: {
    LeaveinfoListContentVue
  },
  data() {
    return {
      data: [],
      pagination: PAGINATION,
      statusCell: TABLE_STATUS_CELL,
      queryParam: {},
      tabListNoTitle: [
        {
          key: 'Municipal',
          tab: '市局班子成员请假 ',
        },
        {
          key: 'county',
          tab: '区县领导外出请假',
        },
        {
          key: 'leader',
          tab: '领导干部外出请假',
        },
        {
          key: 'police',
          tab: '民警请销假',
        },
      ],
      noTitleKey: 'Municipal',
    }
  },
  created() {
    if (this.hasPermissions('edit', 'delete'))
    {
      this.columns.push({
        title: '操作',
        width: 130,
        align: 'center',
        scopedSlots: { customRender: 'action' }
      })
    }
  },
  activated() {
    this.load()
  },
  methods: {
    search() {
      this.pagination.current = 1
      this.load()
    },
    load() {
      this.queryParam.currPage = this.pagination.current
      this.queryParam.pageSize = this.pagination.pageSize
      leaveInfoList({ ...this.queryParam }).then((response) => {
        this.data = response.list
        this.pagination.current = response.currPage
        this.pagination.total = response.totalCount
        this.pagination.pageSize = response.pageSize
      })
    },
    handleTableChange(pagination, filters, sorter) {
      this.pagination = pagination
      this.load()
    },
    handleSave() {
      this.$router.push({
        path: 'add'
      })
    },
    handleEdit(id) {
      this.$router.push({
        path: 'edit',
        query: {
          id: id
        }
      })
    },
    handleDelete(id) {
      const data = []
      data.push(id)
      leaveInfoDel(data).then(() => {
        this.message.success('删除成功')
        this.load()
      })
    },
    onTabChange(key, type) {
      console.log(key, type);
      this[type] = key;
    },
  }
}
</script>
<style>
.actions {
  display: flex;
  justify-content: space-around;
}
</style>
